Skip to content

Allow excluding request logs for URI path patterns.#366

Merged
KarstenSchnitter merged 3 commits intomainfrom
request-log-uri-filter
Apr 2, 2026
Merged

Allow excluding request logs for URI path patterns.#366
KarstenSchnitter merged 3 commits intomainfrom
request-log-uri-filter

Conversation

@KarstenSchnitter
Copy link
Copy Markdown
Contributor

Adresses #324.

Provides an option to suppress request logs for comma-separated ant-like uri patterns. This allows to disable request log generation for health or monitoring endpoints.

The implementation comes with JMH benchmarks to ensure low latency due to filtering. The logback and log4j2 benchmarks were aligned to the servlet approach.

Add servlet init parameter `excludePatterns` to configure a comma-separate list
of ant-like patterns (wildcards "*" and "**") to exclude uris from request log generation.
This can be used to suppress request logs from health or metrics endpoints.

Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>
Add benchmarks to ensure performance of URI filtering. The are executed as part
of the Maven verify lifecycle phase when profile benchmark is active.

The benchmarks show on my machine, that filtering without wildcards adds no more
than 10ns and single wildcard matches no more than 40ns latency.

Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>
All JMH benchmarks now align in the profile benchmark. They can be executed with

mvn verify -P benchmark

Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>
Copy link
Copy Markdown
Contributor

@nicklas-dohrn nicklas-dohrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

@ParameterizedTest
@CsvSource({ "/actuator/**, /actuator/health", "/actuator/**, /actuator/health/liveness",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reading the code and the docs it's quite obvious, but if I filter /actuator/** then /actuator without trailing slash is not covered. Do you think it makes sense to add a test case for this to make it more explicit? I think it doesn't deserve dedicated docs though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be careful to mention this in the documentation. It will be added to the Instrumenting servlets. The pattern is supporting wildcards and them having influence on preceding characters could also be considered strange.

Copy link
Copy Markdown
Contributor

@bennygoerzig bennygoerzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered the performance implications? If users construct complex patterns, this should really get out of hand if I got it correctly. I can't say though how weird the pattern would need to be to slow down the app itself, maybe you can judge this.

Also, since this lib is CF specific, maybe you could a specific example to the docstring (e.g., dropping /health). If you plan to add docs for this anyways, you can disregard this.

@KarstenSchnitter
Copy link
Copy Markdown
Contributor Author

Have you considered the performance implications? If users construct complex patterns, this should really get out of hand if I got it correctly. I can't say though how weird the pattern would need to be to slow down the app itself, maybe you can judge this.

This is what the JMH benchmarks are for. On my machine I get those latency results:

Benchmark                                          Mode  Cnt   Score   Error  Units
RequestUriMatcherBenchmarks.doubleWildcardMatch    avgt    5   9,299 ± 0,568  ns/op
RequestUriMatcherBenchmarks.doubleWildcardNoMatch  avgt    5   4,327 ± 0,440  ns/op
RequestUriMatcherBenchmarks.exactMatch             avgt    5   6,573 ± 0,585  ns/op
RequestUriMatcherBenchmarks.exactNoMatch           avgt    5   3,919 ± 0,251  ns/op
RequestUriMatcherBenchmarks.multiPatternMatch      avgt    5  17,384 ± 0,800  ns/op
RequestUriMatcherBenchmarks.multiPatternNoMatch    avgt    5  17,797 ± 0,687  ns/op
RequestUriMatcherBenchmarks.noPatterns             avgt    5   0,680 ± 0,038  ns/op
RequestUriMatcherBenchmarks.singleWildcardMatch    avgt    5  35,332 ± 3,651  ns/op

@KarstenSchnitter KarstenSchnitter merged commit 58c8f06 into main Apr 2, 2026
3 checks passed
@KarstenSchnitter KarstenSchnitter deleted the request-log-uri-filter branch April 2, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants